#!/bin/bash

# 以用户名为文件名 创建几个文件 文件内容 是用户的id和家目录
#echo ${HOME}
#echo ${PATH}
#echo ${PWD}

echo $0 == $1 == $2 == $3
#exit 222
if [ -z "$1" ]; then
  dest_dir=${HOME}/ideash
else
  dest_dir=$1
fi
echo ${dest_dir}
user_info_location=/etc/passwd
login_style=nologin
size=5

user_table=$(cat ${user_info_location} | grep ${login_style} | head -n ${size})
#echo ${user_table}
#字符串分割split到数组 熟练后可以省略
user_array=(${user_table})
for user_i in ${user_table[*]}; do
  #    echo 用户信息： ${user_i}
  user_i_tuple=(${user_i//:/ })
  #    echo ${user_i_tuple[*]}
  #    echo filename: ${user_i_tuple[0]}
  #    echo content_1: ${user_i_tuple[2]}
  #    echo content_2: ${user_i_tuple[5]}
  echo ${user_i_tuple[2]} : ${user_i_tuple[5]} >>${dest_dir}/${user_i_tuple[0]}.txt
  #    echo ${user_i_tuple[2]} : ${user_i_tuple[5]} >> $1/${user_i_tuple[0]}.txt

done

exit 0